<?php

/*
Zoo Management Simulation
This file provides editing functionality for the cage entry which is continued from the editCage file.
It also updates the database with data from the previous form in the editCage file.
*/

include("dbconnect.php");
if ($_REQUEST['submit'] == "Return to Administator page"){
	header('Location: index.php');
}

$cageid = $_REQUEST['cageid'];
$type = $_REQUEST['type'];

if ($_REQUEST['submit'] == "Edit Cage"){
	$typeSql = "(SELECT Type_Id FROM type WHERE Type_Desc='".$type."')";

	$sql = "UPDATE `cage` SET `Cage_Name`='".$_REQUEST['name']."',`Cage_Length`=".$_REQUEST['length'].",`Cage_Width`=".$_REQUEST['width'].",`Cage_Height`=".$_REQUEST['height'].",`Type_Id`=".$typeSql.",`Exhibit_Name`='".$_REQUEST['exhibitname']."',`Exhibit_Desc`='".$_REQUEST['exhibitdesc']."', `Cage_Human`='".$_REQUEST['humandetector']."' WHERE Cage_Id=".$cageid;
	
	$result = mysql_query($sql);
}




$entrysql = "SELECT Entry_Id FROM entry WHERE Cage_Id=".$cageid;
$entryresult = mysql_query($entrysql);
$numberofEntries = mysql_num_rows($entryresult);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Edit Cage Entries</title>
<link href="mainstyle.css" rel="stylesheet" type="text/css" />
</head>

<body>
<h1>Edit Cage Entries</h1>

<form id="editCageEntryForm" name="editCageEntryForm" method="post" enctype="multipart/form-data" action="editCageEntryProcess.php">
<table id="zootable" width="100%" border="1">
	  <tr>
	    <td id="tableheader">Entry</td>
	    <td id="tableheader"><label for="doortype">Door Type</label></td>
	    <td id="tableheader"><label for="doorstatus">Door Status</label></td>
      </tr>
      
      <?php
      $entrynumber = 1;
	  while(($row = mysql_fetch_row($entryresult)) !== FALSE)
		{
      	echo "<tr>";
	    echo "<td>". $entrynumber . "</td>";
		
	    echo"<td><input type='radio' value='Single' name='doortype".$entrynumber."' id='doortype".$entrynumber."' />Single<br />
        <input type='radio' value='Double' name='doortype".$entrynumber."' id='doortype".$entrynumber."' />Double</td>";
		
	    echo "<td><input type='radio' value='Open' name='doorstatus".$entrynumber."' id='doorstatus".$entrynumber."' />Open<br />
        <input type='radio' value='Closed' name='doorstatus".$entrynumber."' id='doorstatus".$entrynumber."' />Closed</td>";
		echo "<input type='hidden' name='entryid' value='".$row[0] . "' />";
		echo "<td>". "<input type='submit' name='submit' id='submit' value='Delete' />" . "</td>";

      echo "</tr>";
	  $entrynumber+=1;
	  }
	  echo '<input type="hidden" id="numentry" name="numentry" value="'.$numberofEntries.'" />';
	  	  echo '<input type="hidden" id="cageid" name="cageid" value="'.$cageid.'" />';
	  ?>
</table>
<input type="submit" name="submit" id="submit" value="Edit Cage Entries" />
<input type="submit" name="submit" id="submit" value="Return to Administator page" />
</form>
</body>
</html>